import HttpException  from '../exceptions/HttpException';
import { Request, Response, NextFunction } from 'express';
//枚举http的状态码，参考地址：https://www.npmjs.com/package/http-status-codes
import { INTERNAL_SERVER_ERROR  } from 'http-status-codes';

const errorMiddleware = (error:HttpException, _request:Request, response:Response, _next:NextFunction) => {
    response.status(error.status || INTERNAL_SERVER_ERROR).send({
        success: false,
        message: error.message,
        errors:error.errors
    });
};

export default errorMiddleware;